package main

import (
	"context"
	"fmt"
	"go.manyji.com/lib/app"
)

func init() {
	app.Async(func() {
		WaitInit()

		if err := (&data_User{}).loadRole(); err != nil {
			panic(err)
		}
	})
}

func (a *data_Role) Get(ctx context.Context, name, alias string) ([]interface{}, error) {

	var (
		querySQL = fmt.Sprintf(`
			SELECT
				*
			FROM
			    role
			WHERE 
			    %v = '%v' AND %v = '%v'
`, "`name`", name, "`alias`", alias)
	)

	return db.QueryRaw(ctx, querySQL, Role{})
}

func (a *data_Role) IsAdminRoleId(rId uint64) bool {

	return adminRole.ID == int64(rId)
}

func (a *data_Role) GetAgentRole() *Role {
	return agentRole
}

func (a *data_Role) GetAdminRole() *Role {

	return adminRole
}

func (a *data_Role) GetSalespersonRole() *Role {

	return salespersonRole
}

func (a *data_Role) GetChannelAgentRole() *Role {

	return channelAgentRole
}

func (a *data_Role) IsSalespersonRole(rId uint64) bool {

	return salespersonRole.ID == int64(rId)
}

func (a *data_Role) IsAgentRole(rId uint64) bool {

	return agentRole.ID == int64(rId)
}

func (a *data_Role) IsChannelAgentRole(rId uint64) bool {

	return channelAgentRole.ID == int64(rId)
}
